--require "MainScene"
JiaSuSampleDialog={}
JiaSuSampleDialogFunc={}
JiaSuSampleDialogFunc.__index = JiaSuSampleDialogFunc
setmetatable(JiaSuSampleDialog, JiaSuSampleDialogFunc)

JiaSuSampleDialogFunc.create = function(self, leftTime, handler)
  local l = {}
  setmetatable(l, JiaSuSampleDialogFunc)
  l.handler = handler
  l.view = CCBReader:load("JiaSuDialog.ccbi")
  setObjectExtTable(l.view:getChildByTag(1111), l)
  
  setObjectExtTable(l.view:getChildByTag(1020), l)
  setObjectExtTable(l.view:getChildByTag(1021), l)
  
  local min = math.ceil(leftTime/60) 
  l.cost = min
  local tmp = string.format("当前剩余%s，是否需要加速完成？需要消耗%d个时间卷轴或%d个军饷。", formatSecond(leftTime), min, min)
  TypeCast(l.view:getChildByTag(1011), "CCLabelTTF"):setString(autoEnter(tmp, 48)) 
 
  --加速卷轴id=11 
  TypeCast(l.view:getChildByTag(1012), "CCLabelTTF"):setString(string.format("%d/%d", min, ItemManager:getItemCount(11))) 
  TypeCast(l.view:getChildByTag(1013), "CCLabelTTF"):setString(string.format("%d/%d", min, UserData.userinfo.host.coin)) 

  return l
end
JiaSuSampleDialogFunc.onJuanZhouButton = function(self, node, event)
  local metaFunc = getmetatable(self.handler)
  if metaFunc["onJiaSuConfirm"]~=nil then
    metaFunc["onJiaSuConfirm"](self.handler, self, true, "true", self.cost)
  end
end
JiaSuSampleDialogFunc.onJunXiangButton = function(self, node, event)
  local metaFunc = getmetatable(self.handler)
  if metaFunc["onJiaSuConfirm"]~=nil then
    metaFunc["onJiaSuConfirm"](self.handler, self, true, "false", self.cost)
  end
end
JiaSuSampleDialogFunc.onClose = function(self, node, event)
  --node:getParent():getParent():removeChild(node:getParent(), true)
  local metaFunc = getmetatable(self.handler)
  if metaFunc["onJiaSuConfirm"]~=nil then
    metaFunc["onJiaSuConfirm"](self.handler, self, false, "true", self.cost)
  end
end
